package com.ihr360.excel.controller;

import com.ihr360.commons.entity.AuthUserInfo;
import com.ihr360.commons.vo.ResultInfo;
import com.ihr360.excel.annotation.InterruptIgnore;
import com.ihr360.excel.service.ExcelService;
import com.ihr360.excel.vo.ImportResult;
import com.ihr360.excel.vo.ProgressContext;
import com.ihr360.excel.vo.ProgressResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/excelCloud")
public class ExcelController {

    @Autowired
    private ExcelService excelService;

    @Async
    @PostMapping("/handleProcess")
    @InterruptIgnore
    public void doHandleExcelFileProcess(@RequestBody ProgressContext progressContext, AuthUserInfo authUserInfo) throws InterruptedException {
        excelService.doHandleExcelFileProcess(progressContext);
    }

    @PostMapping("/processorJournal")
    @InterruptIgnore
    public void saveExcelProcessorJournal(@RequestBody ProgressContext progressContext, @RequestParam String errorMsg) {
        excelService.saveExcelProcessorJournal(progressContext, errorMsg);
    }

    @PostMapping("/progressResult")
    @InterruptIgnore
    public ProgressResult getProgressResult(@RequestBody ProgressContext progressContext) {
        return excelService.getProgressResult(progressContext);
    }

    @PostMapping("/importResult")
    public ImportResult getImportResult(@RequestBody ProgressContext progressContext) {
        return excelService.getImportResult(progressContext);
    }

    @PostMapping("/interruptProgress")
    @InterruptIgnore
    public ResultInfo interruptProgress(@RequestBody ProgressContext progressContext) {
        return excelService.interruptProgress(progressContext);
    }

    @PostMapping("/errorFileId")
    @InterruptIgnore
    public String getErrorFileId(@RequestBody ProgressContext progressContext) {
        return excelService.getErrorFileId(progressContext);
    }

}
